package com.bwie.home.common.config;

import com.bwie.home.common.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Random;

public class CreateToken {
    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private StringRedisTemplate redisTemplate;

    public static final String TOKEN_PREFIX = "home:token:";

    public String create(String subject, String roles) {
        int i = new Random().nextInt(10000);
        String token = jwtUtil.createJWT(String.valueOf(i), subject, roles);
        redisTemplate.opsForValue().set(TOKEN_PREFIX,token);
        return token;
    }
}
